package com.example.rpAdapter.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.common.annotation.ResponseResult;
import com.example.common.handler.ResponseResultHandler;
import com.example.config.util.SecurityUtil;
import com.example.rpapp.user.query.UserLoginQueryExe;
import com.example.rpclient.UserRegisterCmd;
import com.example.rpclient.api.IUserService;
import com.example.rpclient.dto.UserUpdateCmd;
import com.example.rpclient.dto.data.UserVo;
import com.example.rpclient.dto.query.UserListByParamQuery;
import com.example.rpclient.dto.query.UserLoginQuery;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@AllArgsConstructor
@ResponseResult
@RequestMapping("/v1/user")
public class UserController {

    private final IUserService userService;

    private final ResponseResultHandler responseResultHandler;

    @PostMapping("/register")
    public UserVo register(@Validated @RequestBody UserRegisterCmd cmd){
        return userService.register(cmd);
    }

    @PostMapping("/login")
    public String login(@Validated @RequestBody UserLoginQuery query){
        System.out.println("==================================");
        System.out.println(responseResultHandler);
        System.out.println("==================================");
        return userService.login(query);
    }



    @GetMapping("/one")
    public UserVo one(@RequestParam(value = "id") Long id){
        System.out.println("==================================");
        System.out.println("id:"+SecurityUtil.getUserId());
        System.out.println("==================================");
        return userService.one(id);
    }

    @PostMapping("/update")
    public UserVo update(@Validated @RequestBody UserUpdateCmd cmd){
        return userService.update(cmd);
    }


}
